
/*
** world.c for zomzom in /home/goupil_r//GameInLab/game1
**
** Made by robin goupil
** Login   <goupil_r@epitech.net>
**
** Started on  Thu Nov 15 18:21:12 2012 robin goupil
** Last update Sun Nov 18 16:22:19 2012 robin goupil
*/

#include <SDL/SDL.h>
#include "include/struct.h"
#include "include/world.h"
#include "include/my.h"

t_world		*create_world(char *bg_path, int size_x, int size_y, SDL_Surface *screen)
{
  t_world	*world;

  world = xmalloc(sizeof(*world));
  world->size_x = size_x;
  world->size_y = size_y;
  world->background = SDL_LoadBMP(bg_path);
  world->background->w = size_x;
  world->background->h = size_y;
  world->background_pos.x = 0;
  world->background_pos.y = 0;
  world->screen = screen;
  world->reticle = NULL;
  world->player = NULL;
  world->zombie = NULL;
  return (world);
}

void		put_reticle_in_world(t_world *world, t_reticle *reticle)
{
  if (world == NULL || reticle == NULL)
    {
      printf("Error: Couldn't assign reticle to world: NULL value.\n");
      exit(EXIT_FAILURE);
    }
  world->reticle = reticle;
}

void		put_player_in_world(t_world *world, t_player *player)
{
  if (world == NULL || player == NULL)
    {
      printf("Error: Couldn't assign player to world: NULL value.\n");
      exit(EXIT_FAILURE);
    }
  world->player = player;
}

void		put_zombie_in_world(t_world *world, t_zombie *zombie)
{
  if (world == NULL || zombie == NULL)
    {
      printf("Error: Couldn't assign zombie to world: NULL value.\n");
      exit(EXIT_FAILURE);
    }
  zombie->next = world->zombie;
  if (world->zombie)
      world->zombie->prev = zombie;
  world->zombie = zombie;
}
